let isClick = false

/**
 * @description: 封装发送方法
 * @param {*} message
 * @param {*} callback
 * @return {*}
 */
 function sendMessage(message, callback){
    return new Promise((resolve, reject)=>{
        try {
            chrome.tabs.query({currentWindow: true, active: true}, tabs => {
                chrome.tabs.sendMessage(tabs[0].id, message, (response) => {
                    callback && callback(response)
                    resolve(response)
                });
            });
        } catch (error) {
            reject(error)
        }
    })
}

/**
 * @description: 停止按钮事件
 * @return {*}
 */
function addSubmitListener(){
    $('#stop').click(async () => {
        if(isClick) return
        isClick = true
        await sendMessage({type: 'stop'}, (response) => {
            console.log('stop stop stop - -   response - - -      ', response)
            
        })
    })
}

document.addEventListener('DOMContentLoaded', () => {
    addSubmitListener()
})


